﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ePlanet.Entities;

namespace FilesUpload
{
    public partial class SelectUploadArchive : Form
    {
        public SelectUploadArchive()
        {
            InitializeComponent();
            this.dataGridView1.AutoGenerateColumns = false;
        }

        public IList<BindingItem> Entities
        {
            get
            {
                List<BindingItem> items = new List<BindingItem>();
                foreach (DataGridViewRow row in this.dataGridView1.Rows)
                {
                    BindingItem item = row.DataBoundItem as BindingItem;
                    if (item!=null)
                    {
                        items.Add(item);
                    }
                }
                return items;
            }
            set
            {
                this.dataGridView1.DataSource = value;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in this.dataGridView1.Rows)
            {
                BindingItem item = row.DataBoundItem as BindingItem;
                row.SetValues(true);
            }
            this.dataGridView1.EndEdit();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in this.dataGridView1.Rows)
            {
                BindingItem item = row.DataBoundItem as BindingItem;
                row.SetValues(false);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }

    public class BindingItem
    {
        public string DataBaseId { get; set; }
        public string DataId { get; set; }
        public string ArchiveNum { get; set; }
        public bool IsSelect { get; set; }
        public string Title { get; set; }
    }
}
